<?php
require dirname(__DIR__).'/unit_test_conf.php';
require __DIR__.'/Class.php';
define('NAME', basename(__DIR__));

/**
 *	
 */
class UnitTest extends PHPUnit_Framework_TestCase
{
	################################################################################################################################
	#	1. Setting Basic varialbes for Testing..
	################################################################################################################################
	protected static $error;
	protected static $bbs_seq;
	
	################################################################################################################################
	#	2. Basic Method Testing..
	################################################################################################################################

	/**
	 * 
	 */
	public function testInsert4Class()
	{
		try
		{
			$o = Wdk::get(NAME);
			$o['bbs_id']				= utRc(rand(5,10));
			$o['bbs_name']				= utRc(rand(5,10));
			$o['bbs_header']			= utRc(rand(40,50));
			$o['bbs_footer']			= utRc(rand(40,50));
			$o['bbs_listsize']			= utRand(10,15,20);
			$o['bbs_pagesize']			= utRand(5,10,15);
			$o['bbs_file_flag']			= utRand('T', 'F');
			$o['bbs_file_num']			= rand(1,5);
			$o['bbs_file_size']			= rand(1,10);
			$o['bbs_file_type']			= utRand('*', 'jpg', 'gif', 'txt');
			$o['bbs_skin']				= utRand('default', 'faq', 'gallery');
			$o['bbs_category_flag']		= utRand('T', 'F');
			$o['bbs_comment_flag']		= utRand('T', 'F');
			$o['bbs_recommend_flag']	= utRand('T', 'F');
			$o['bbs_use_flag']			= utRand('T', 'F');
			$o['bbs_secure_flag']		= utRand('T', 'F');
			$o['bbs_captcha_flag']		= utRand('T', 'F');
			$o->insert();

			self::$bbs_seq = $o['bbs_seq'];
			/************************************************************************************************************************/
			//	Compare Both Data..
			/************************************************************************************************************************/
			$c = Wdk::get(NAME);
			$c->load(self::$bbs_seq);
			$this->assertEquals($o['bbs_id']				, $c['bbs_id']				, "[Error] bbs_id");
			$this->assertEquals($o['bbs_name']				, $c['bbs_name']			, "[Error] bbs_name");
			$this->assertEquals($o['bbs_header']			, $c['bbs_header']			, "[Error] bbs_header");
			$this->assertEquals($o['bbs_footer']			, $c['bbs_footer']			, "[Error] bbs_footer");
			$this->assertEquals($o['bbs_listsize']			, $c['bbs_listsize']		, "[Error] bbs_listsize");
			$this->assertEquals($o['bbs_pagesize']			, $c['bbs_pagesize']		, "[Error] bbs_pagesize");
			$this->assertEquals($o['bbs_file_flag']			, $c['bbs_file_flag']		, "[Error] bbs_file_flag");
			$this->assertEquals($o['bbs_file_num']			, $c['bbs_file_num']		, "[Error] bbs_file_num");
			$this->assertEquals($o['bbs_file_size']			, $c['bbs_file_size']		, "[Error] bbs_file_size");
			$this->assertEquals($o['bbs_file_type']			, $c['bbs_file_type']		, "[Error] bbs_file_type");
			$this->assertEquals($o['bbs_skin']				, $c['bbs_skin']			, "[Error] bbs_skin");
			$this->assertEquals($o['bbs_category_flag']		, $c['bbs_category_flag']	, "[Error] bbs_category_flag");
			$this->assertEquals($o['bbs_comment_flag']		, $c['bbs_comment_flag']	, "[Error] bbs_comment_flag");
			$this->assertEquals($o['bbs_recommend_flag']	, $c['bbs_recommend_flag']	, "[Error] bbs_recommend_flag");
			$this->assertEquals($o['bbs_use_flag']			, $c['bbs_use_flag']		, "[Error] bbs_use_flag");
			$this->assertEquals($o['bbs_secure_flag']		, $c['bbs_secure_flag']		, "[Error] bbs_secure_flag");
			$this->assertEquals($o['bbs_captcha_flag']		, $c['bbs_captcha_flag']	, "[Error] bbs_captcha_flag");
			$this->assertEquals('F'							, $c['bbs_del_flag']		, "[Error] bbs_del_flag");
			/************************************************************************************************************************/
		}
		catch(WException $e)
		{
			self::$error = true;
			$this->assertTrue(False, 'Exception - '.$e->getMessage());
		}
	}
	
	
	/**
	 *	
	 */
	public function testUpdate4Class()
	{
		if(self::$error == true) return;
		try
		{
			$o = Wdk::get(NAME);
			$o->load(self::$bbs_seq);
			$o['bbs_name']				= utRc(rand(5,10));
			$o['bbs_header']			= utRc(rand(40,50));
			$o['bbs_footer']			= utRc(rand(40,50));
			$o['bbs_listsize']			= utRand(10,15,20);
			$o['bbs_pagesize']			= utRand(5,10,15);
			$o['bbs_file_flag']			= utRand('T', 'F');
			$o['bbs_file_num']			= rand(1,5);
			$o['bbs_file_size']			= rand(1,10);
			$o['bbs_file_type']			= utRand('*', 'jpg', 'gif', 'txt');
			$o['bbs_skin']				= utRand('default', 'faq', 'gallery');
			$o['bbs_category_flag']		= utRand('T', 'F');
			$o['bbs_comment_flag']		= utRand('T', 'F');
			$o['bbs_recommend_flag']	= utRand('T', 'F');
			$o['bbs_use_flag']			= utRand('T', 'F');
			$o['bbs_secure_flag']		= utRand('T', 'F');
			$o['bbs_captcha_flag']		= utRand('T', 'F');
			$o->update();
			
			/************************************************************************************************************************/
			//	Compare Both Data..
			/************************************************************************************************************************/
			$c = Wdk::get(NAME);
			$c->load(self::$bbs_seq);
			$this->assertEquals($o['bbs_name']				, $c['bbs_name']			, "[Error] bbs_name");
			$this->assertEquals($o['bbs_header']			, $c['bbs_header']			, "[Error] bbs_header");
			$this->assertEquals($o['bbs_footer']			, $c['bbs_footer']			, "[Error] bbs_footer");
			$this->assertEquals($o['bbs_listsize']			, $c['bbs_listsize']		, "[Error] bbs_listsize");
			$this->assertEquals($o['bbs_pagesize']			, $c['bbs_pagesize']		, "[Error] bbs_pagesize");
			$this->assertEquals($o['bbs_file_flag']			, $c['bbs_file_flag']		, "[Error] bbs_file_flag");
			$this->assertEquals($o['bbs_file_num']			, $c['bbs_file_num']		, "[Error] bbs_file_num");
			$this->assertEquals($o['bbs_file_size']			, $c['bbs_file_size']		, "[Error] bbs_file_size");
			$this->assertEquals($o['bbs_file_type']			, $c['bbs_file_type']		, "[Error] bbs_file_type");
			$this->assertEquals($o['bbs_skin']				, $c['bbs_skin']			, "[Error] bbs_skin");
			$this->assertEquals($o['bbs_category_flag']		, $c['bbs_category_flag']	, "[Error] bbs_category_flag");
			$this->assertEquals($o['bbs_comment_flag']		, $c['bbs_comment_flag']	, "[Error] bbs_comment_flag");
			$this->assertEquals($o['bbs_recommend_flag']	, $c['bbs_recommend_flag']	, "[Error] bbs_recommend_flag");
			$this->assertEquals($o['bbs_use_flag']			, $c['bbs_use_flag']		, "[Error] bbs_use_flag");
			$this->assertEquals($o['bbs_secure_flag']		, $c['bbs_secure_flag']		, "[Error] bbs_secure_flag");
			$this->assertEquals($o['bbs_captcha_flag']		, $c['bbs_captcha_flag']	, "[Error] bbs_captcha_flag");
			$this->assertEquals('F'							, $c['bbs_del_flag']		, "[Error] bbs_del_flag");
			/************************************************************************************************************************/
		}
		catch(WException $e)
		{
			self::$error = true;
			$this->assertTrue(False, 'Exception - '.$e->getMessage());
		}
	}
	
	
	/**
	 *	
	 */
	public function testDelete4Class()
	{
		if(self::$error == true) return;
		try
		{
			$o = Wdk::get(NAME);
			$o->load(self::$bbs_seq);
			$o->delete();
			/************************************************************************************************************************/
			//	Compare Both Data..
			/************************************************************************************************************************/
			$c = Wdk::get(NAME);
			$c->load(self::$bbs_seq);
			$this->assertEquals('T'	, $c['bbs_del_flag']	, "[Error] bbs_del_flag");
			/************************************************************************************************************************/
		}
		catch(WException $e)
		{
			self::$error = true;
			$this->assertTrue(False, 'Exception - '.$e->getMessage());
		}
	}
	
	################################################################################################################################
	#	3. Manager Method Testing..
	################################################################################################################################
	/**
	 * 
	 */
	public function testLoad4Manager()
	{
		if(self::$error == true) return;
		try
		{
			$cm = Wdk::get(NAME.'Manager');
			$cm->load();
		}
		catch(NoRecordException $e){}
		catch(WException $e)
		{
			self::$error = true;
			$this->assertTrue(False, 'Exception - '.$e->getMessage());
		}
	}
	
	################################################################################################################################
	#	4. Scenario Testing..
	#	-> a)
	################################################################################################################################
	
	################################################################################################################################
	#	5. Testing tool Methods
	################################################################################################################################
	private function removeTestData()
	{

	}
	public function setUp()
	{
		//	no need..
	}
	public function tearDown()
	{
		//	no need..
	}
	################################################################################################################################
}
?>